﻿using Loki;
using Loki.Engine;
using Luna.Model;
using Luna.Model.Accounting;
using Luna.Model.Project;

namespace Luna.UI
{
    public static class Synchronizer
    {
        private static LunaModel ApplicationModel
        {
            get { return ContextHelper.GetApplicationModel<LunaModel>(); }
        }

        public static void FromAccountingCategories(LokiCollection<DisplayNamedEntity> P_Store)
        {
            P_Store.Synchronize<IAccountingCategory>(
                ApplicationModel.Accounting.Categories,
                (i, d) => { d.ID = i.ID; d.Name = i.Name; d.Description = i.Description; },
                (i, d) => i.ID == d.ID,
                x => x.Name);
        }

        public static void FromProjects(LokiCollection<DisplayNamedEntity> P_Store)
        {
            P_Store.Synchronize<IProject>(
                ApplicationModel.Project.Projects,
                (i, d) => { d.ID = i.ID; d.Name = i.Name; d.Description = i.Description; },
                (i, d) => i.ID == d.ID,
                x => x.Name);
        }

        public static void FromAccounts(LokiCollection<DisplayNamedEntity> P_Store)
        {
            P_Store.Synchronize<IAccount>(
                ApplicationModel.Accounting.Accounts,
                (i, d) => { d.ID = i.ID; d.Name = i.Name; d.Description = i.Name; },
                (i, d) => i.ID == d.ID,
                x => x.Name);
        }
    }
}
